package com.xzg.gulimall.seckill.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


/*
*
* */
@EnableScheduling  //开启定时任务功能  自动配置类 TaskSchedulingAutoConfiguration
@EnableAsync   //开启异步任务功能  自动配置类 TaskExecutionAutoConfiguration
@Component
@Slf4j
public class helloSchedule {
    /*
    定时任务不应该阻塞
      1、可以让业务运行以异步的方式，自己提交到线程池  CompletableFuture.runAsync(()->{},executor);
      2、定时任务支持线程池，配置 spring.task.scheduling.pool.size=5
      3、让定时任务异步执行
    * */
    @Async  //给希望异步执行的方法上标注
    //@Scheduled(cron = "* * * * * ?")  //开启一个定时任务
    public void Hello() throws InterruptedException {
        log.info("hello..");
        Thread.sleep(3000);
    }
}
